class Solution:
    def monotoneIncreasingDigits(self, N: int) -> int:
        if N < 10:
            return N
        length = len(str(N))

        def check(num):
            s = str(num)
            for i in range(len(s) - 1):
                if s[i] > s[i + 1]:
                    return i
            return -1

        n = N
        i = 0
        while (i := check(n)) != -1:
            s = str(n)
            print("i=", i)
            print("[i]=", s[i])
            print(i, s[:i], str(int(s[i]) - 1), len(s[i + 1 :]) * "9")
            n = int(s[:i] + str(int(s[i]) - 1) + len(s[i + 1 :]) * "9")
            print(n)
        return n
